<%@page import="cn.lily.com.enviroment.Enviroment"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.lily.web.util.context.WebContext" %>
<%@ page import="cn.lily.esb.context.AuthEntity" %>
<%@page import="cn.lily.com.db.DBFactory"%>
<%@page import="app.portal.util.EnumValue"%>
<%@page import="cn.lily.com.db.sql.DBManager"%>
<%@page import="cn.lily.com.db.container.reader.DataTable"%>
<%@ page import="cn.lily.inst.web.frames.FrameConfig" %>
<%@ page import="cn.lily.com.configure.util.ESBSetting"%>
<%@ include file="/frames/logbegin.jsp" %>
<%
  String skinName = "";
  String contextPath ="";
  AuthEntity authEntity = (AuthEntity) session.getAttribute(WebContext.LOG_AUTH_CONTEXT);
  if (authEntity != null) {
    skinName = authEntity.getSkinName();
    contextPath = authEntity.getContextPath();
  }
  FrameConfig.setContextPath(contextPath);
  String baseSql="";
  String typeSql="";
  String appSql="";
  //管理员:显示管理应用
  if(EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())){
  		if(EnumValue.COMM_TYP_0.equals(authEntity.getOperEntity().getCommEntity().getCommTyp())) {
  			 baseSql =" SELECT ai.pw_app_id,ai.app_nam,ai.sign_ico,ai.app_path,ai.apps_des,ai.app_id,ai.link_typ,ai.SYS_TYP,tt.TYP_NAM "+
  					  " FROM ${schema}.pw_app_detail ai RIGHT JOIN ${schema}.PW_APP_VER_PUBLISH avp ON ai.pw_app_id=avp.pw_app_id LEFT JOIN ${schema}.PT_SYS_TYPE tt ON ai.SYS_TYP=tt.SYS_TYP "+
  	  				  " WHERE ai.app_sta='"+EnumValue.APP_STA_1+
  					  "' and avp.apptype IN ('"+EnumValue.APPTYPE_0+"','"+EnumValue.APPTYPE_1+"','"+EnumValue.APPTYPE_4+"') "+
  	  				  " and (ai.link_typ ='"+EnumValue.LINK_TYP_0+"' or (ai.link_typ in ('"+EnumValue.LINK_TYP_1+"','"+EnumValue.LINK_TYP_2+"')"+
  	  				  " and EXISTS ( select 1 from ${schema}.pw_app_oper where pw_app_id=ai.pw_app_id and OPER_KEY='"+authEntity.getOperatorId()+"')"+
  					  ")) order by ai.pw_app_id ";
  		}else if(EnumValue.COMM_TYP_1.equals(authEntity.getOperEntity().getCommEntity().getCommTyp())) {
  			 baseSql =" SELECT ai.pw_app_id,ai.app_nam,ai.sign_ico,ai.app_path,ai.apps_des,ai.app_id,ai.link_typ,ai.SYS_TYP,tt.TYP_NAM "+
  					  " FROM ${schema}.pw_app_detail ai RIGHT JOIN ${schema}.PW_APP_VER_PUBLISH avp ON ai.pw_app_id=avp.pw_app_id LEFT JOIN ${schema}.PT_SYS_TYPE tt ON ai.SYS_TYP=tt.SYS_TYP "+
  	  				  " WHERE ai.app_sta='"+EnumValue.APP_STA_1+
  	  				  "' and ((avp.apptype in ('"+EnumValue.APPTYPE_0+"','"+EnumValue.APPTYPE_2+"','"+EnumValue.APPTYPE_4+"') "+
  	  				  " and avp.trad_typ='"+authEntity.getOperEntity().getCommEntity().getTradTyp()+"') or ai.pw_app_id in('000078','000070')) "+
  	  				  " and (ai.link_typ ='"+EnumValue.LINK_TYP_0+"' or (ai.link_typ in ('"+EnumValue.LINK_TYP_1+"','"+EnumValue.LINK_TYP_2+"')"+
 	  				  " and EXISTS ( select 1 from ${schema}.pw_app_oper where pw_app_id=ai.pw_app_id and OPER_KEY='"+authEntity.getOperatorId()+"')"+
 					  ")) order by ai.pw_app_id ";
  		}else{
  			 baseSql =" SELECT ai.pw_app_id,ai.app_nam,ai.sign_ico,ai.app_path,ai.apps_des,ai.app_id,ai.link_typ,ai.SYS_TYP,tt.TYP_NAM "+
  					  " FROM ${schema}.pw_app_detail ai RIGHT JOIN ${schema}.PW_APP_VER_PUBLISH avp ON ai.pw_app_id=avp.pw_app_id LEFT JOIN ${schema}.PT_SYS_TYPE tt ON ai.SYS_TYP=tt.SYS_TYP "+
  	  				  " WHERE ai.app_sta='"+EnumValue.APP_STA_1+
  	  				  "' and (((avp.apptype IN ('"+EnumValue.APPTYPE_0+"','"+EnumValue.APPTYPE_4+"')"+
  	  				  " or (avp.apptype='"+EnumValue.APPTYPE_3+"' and avp.comm_lev >='"+ authEntity.getOperEntity().getCommEntity().getCommLev()+"'))"+
  	  				  " and avp.trad_typ='"+authEntity.getOperEntity().getCommEntity().getTradTyp()+ "') or ai.pw_app_id='000078')  "+
  	  				  " and (ai.link_typ ='"+EnumValue.LINK_TYP_0+"' or (ai.link_typ in ('"+EnumValue.LINK_TYP_1+"','"+EnumValue.LINK_TYP_2+"')"+
 	  				  " and EXISTS ( select 1 from ${schema}.pw_app_oper where pw_app_id=ai.pw_app_id and OPER_KEY='"+authEntity.getOperatorId()+"')"+
 					  ")) order by ai.pw_app_id ";
  		}
  //员工:显示被授权应用	  
  }else{
  		baseSql="select DISTINCT ai.pw_app_id,ai.app_nam,ai.sign_ico,ai.app_path,ai.apps_des,ai.app_id,ai.link_typ,ai.SYS_TYP,di.TYP_NAM "+
	  	" from ${schema}.PW_APP_DETAIL ai RIGHT JOIN ${schema}.PW_APP_VER_PUBLISH bi ON ai.pw_app_id=bi.pw_app_id LEFT JOIN ${schema}.PT_SYS_TYPE di ON ai.sys_typ=di.sys_typ "+
  		" where ai.app_sta='"+EnumValue.APP_STA_1+
  		"' and ai.pw_app_id in "+
	  	" ((select y.pw_app_id from ${schema}.PW_ROLE_RES x,pw_app_model y where x.mode_id=y.mode_id and x.role_id in (select m.role_id from ${schema}.pw_oper_role m,${schema}.pw_role n where  m.role_id=n.role_id and m.oper_key='"+authEntity.getOperatorId()+"' and n.status='1') "+
  		" union select pw_app_id from ${schema}.PW_APP_OPER where oper_key='"+authEntity.getOperatorId()+"')) ";
  }
  
  typeSql="SELECT DISTINCT SYS_TYP,TYP_NAM FROM ("+baseSql+") order by sys_typ ";
  DBManager dbManager=DBFactory.getActionDB();
  DataTable typeTable=dbManager.executeQueryTable(typeSql);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta charset=utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%=FrameConfig.getAppName()%></title>
  	<link href="/<%=ESBSetting.getString("appCode")%>/public/style/skin_bootstrap/bootstrap-3.3.0/bootstrap.css" rel="stylesheet" media="screen">
	<link href="/<%=ESBSetting.getString("appCode")%>/public/font/awesome/font-awesome-4.7.0.css" rel="stylesheet">
    <link href="<%=FrameConfig.getCSSPath("app.css") %>" rel="stylesheet" />

</head>
<body>
    <%
      while(typeTable.next()){
      	appSql="SELECT pw_app_id,app_nam,sign_ico,app_path,app_id,link_typ,SYS_TYP,TYP_NAM FROM ("+baseSql+") WHERE SYS_TYP='"+typeTable.getString("SYS_TYP")+"'";
      	DataTable appTable=dbManager.executeQueryTable(appSql);
      	%>
      	<div class="row">
      	<div class="bar"><div class="bar-left"></div><div class="bar-center"><%=typeTable.getString("TYP_NAM")%></div><div class="bar-right"></div></div>
      	
      	<%
      	while(appTable.next()){
      		String link_typ=appTable.getString("link_typ");
      		String pw_app_id=appTable.getString("pw_app_id");
      		String sysid=appTable.getString("app_id");
      		String app_path=appTable.getString("app_path");
        %>
        <div class="span2" style="width:140px;float:left;margin-left:20px;min-height:1px;">
          <a href="javascript:void(0)" onclick="openapp(this)"  appid="<%=pw_app_id %>" link_typ="<%=link_typ %>" sysid="<%=sysid %>"  app_path="<%=app_path %>"  appname="<%=appTable.getString("APP_NAM") %>">
            <% 
              String sign_ico=appTable.getString("SIGN_ICO");
              if(sign_ico==null || "".equals(sign_ico.trim())){
                sign_ico=FrameConfig.getSkinImg("appappfile/default.png");
              }
              /* 添加WebRoot下图片 */
              if(sign_ico.startsWith("//")){
            	  sign_ico = FrameConfig.getWebRootImg(sign_ico.substring(1));
              }
              
            %>
            <img src="<%=sign_ico %>" alt="" style="width:75px;height:75px;"/>
            <div><%=appTable.getString("APP_NAM") %></div>
          </a>
        </div>
        <%
      	}
      	%>

      </div>
    <%
      }
    dbManager.free();
    %>
    <%@ include file="/frames/logend.jsp" %>
 
  <script src="<%=FrameConfig.getBaseJsUrl() %>/common/jquery-1.9.1.min.js"></script>
  <script src="/<%=ESBSetting.getString("appCode")%>/public/js/skin_bootstrap/bootstrap-3.3.0/bootstrap-3.3.0.js"></script>
  <script src="<%=FrameConfig.getJsUrl("app.js")%>"></script>
</body>
</html>

